﻿using HQHS.Library.DAL.Administrator.Sprocs;
using HQHS.Library.DAO.Administrator;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HQHS.Library.DAL.Administrator
{
    public class AdministratorMgr
    {
        public static IList<AdministratorInfo> GetMenus_ByType(int id, string name, string pwd, byte? type)
        {
            using (Administrator_Load_p cmd = new Administrator_Load_p())
            {
                cmd.Parameters.ID = id;
                cmd.Parameters.UserName = name;
                cmd.Parameters.Password = pwd;
                cmd.Parameters.Type = type;
                using (GOTSqlConnectionManager cm = new GOTSqlConnectionManager())
                {
                    using (SqlDataReader reader = cm.ExecuteReader(cmd))
                    {
                        return AdministratorInfoAssembler.CreateList(reader);
                    }
                }
            }
        }
        public static int Save(AdministratorInfo info, int type)
        {
            using (Administrator_Save_p cmd = new Administrator_Save_p())
            {
                cmd.Parameters.ID = info.ID;
                cmd.Parameters.UserName = info.UserName;
                cmd.Parameters.Password = info.Password;
                cmd.Parameters.UserType = info.UserType;
                cmd.Parameters.IsActive = info.IsActive;
                cmd.Parameters.LoginStatus = info.LoginStatus;
                cmd.Parameters.Type = type;
                using (GOTSqlConnectionManager cm = new GOTSqlConnectionManager())
                {
                    cm.ExecuteNonQuery(cmd);
                    return cmd.Parameters.ID;
                }
            }
        }
    }
}
